package me.zhengjie.poemQuestions.rest;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import me.zhengjie.annotation.AnonymousAccess;
import me.zhengjie.annotation.Log;
import me.zhengjie.poemQuestions.domain.UserAnswerRecord;
import me.zhengjie.poemQuestions.domain.vo.UserAnswerRecordQueryCriteria;
import me.zhengjie.poemQuestions.service.UserAnswerRecordService;
import me.zhengjie.utils.PageResult;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@RestController
@RequiredArgsConstructor
@RequestMapping("/api/answers")
@Api(tags = "【答题模块】用户答题接口")
@Validated
public class UserAnswerRecordController {

    private final UserAnswerRecordService userAnswerRecordService;
    @Log("查询答题记录")
    @ApiOperation("查询答题记录")
    @GetMapping
    @AnonymousAccess
    public ResponseEntity<PageResult<UserAnswerRecord>> pagedQueryPoemPoet(UserAnswerRecordQueryCriteria criteria,
                                                                           Page<Object> page){
        return new ResponseEntity<>(userAnswerRecordService.queryAll(criteria,page), HttpStatus.OK);
    }

    @Log("提交并校验用户答案")
    @ApiOperation("提交并校验用户答案")
    @PostMapping("/submit")
    @AnonymousAccess
    public ResponseEntity<String> submitAnswer(@Valid @RequestBody UserAnswerRecord record) {
        String result = userAnswerRecordService.checkAndSaveAnswer(record);
        return ResponseEntity.ok(result);
    }


}
